package com.weavernorth.humanresource;

import com.engine.kq.biz.KQFormatData;
import com.weavernorth.attendance.util.ToSapUtil;
import com.weavernorth.create.TimeResume;
import org.apache.commons.logging.Log;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;

import java.util.Calendar;

/**
 * @program: ecology_erdos
 * @description: 定时刷新考勤报表中的离职人员
 * @author: zm
 * @create: 2020-07-10 10:43
 **/


public class RefreshKqTable extends BaseCronJob {
    private static Log log = org.apache.commons.logging.LogFactory.getLog(RefreshKqTable.class.getName());

    @Override
    public void execute() {
        //数据库操作
        RecordSet rs=new RecordSet();
        //获取当前日期
        String strDate = DateUtil.getCurrentDate();
        //上个月第一天
        String strLastDay=ToSapUtil.getPreMonthFirstDate();
        //查询这之间的离职人员
        String strSql="select id, enddate from hrmresource where status='5' and enddate>=? and enddate<=?";
        log.info("查询离职人员信息:"+strSql+",strLastDay:"+strLastDay+",strDate:"+strDate);
        rs.executeQuery(strSql,strLastDay,strDate);
        while (rs.next()){
            String resourceid= Util.null2String(rs.getString("id"));
            log.info("人员id:"+resourceid);
            String enddate=Util.null2String(rs.getString("enddate"));

            KQFormatData kqFormatData = new KQFormatData();
            if(resourceid.length()>0 && enddate.length()>0 && strDate.length()>0) {
                Calendar cal = DateUtil.getCalendar();

                boolean isEnd = false;
                for (String date = enddate; !isEnd; ) {
                    if (date.equals(strDate)) isEnd = true;
                    kqFormatData.formatKqDate(resourceid, date);
                    cal.setTime(DateUtil.parseToDate(date));
                    date = DateUtil.getDate(cal.getTime(), 1);
                }
              log.info("报表刷新成功!");
            }
        }



    }
}
